package com.jiukuaidao.zhulin.adapter;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * Author : H_Joker
 * Date : 2016/5/26
 * Description :
 */
public class MainHomePagerAdapter extends FragmentPagerAdapter {

    private List<Fragment> mFragments;

    public MainHomePagerAdapter(FragmentManager fm) {
        super(fm);
    }

    public void addFragment(Fragment fragment) {
        if (mFragments == null) {
            mFragments = new ArrayList<>();
        }
        mFragments.add(fragment);
    }

    @Override
    public Fragment getItem(int position) {
        if (mFragments.size() <= position) {
            return null;
        }

        return mFragments.get(position);
    }

    @Override
    public int getCount() {
        return mFragments == null ? 0 : mFragments.size();
    }
}
